package day19;

public class SaleTicket extends Thread{
    private static int ticket = 200;
    public SaleTicket(){

    }

    public static int getTicket() {
        return ticket;
    }

    @Override
    public void run() {
        for (int i =1;i<=50;i++){
            try {
                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
//            synchronized (this){
//                System.out.println(Thread.currentThread().getName()+"---卖出第"+(ticket--)+"张票");
//            }
            saleSafe();
        }
    }
    private synchronized void saleSafe(){
        System.out.println(Thread.currentThread().getName()+"---卖出第"+(ticket--)+"张票");
    }
}
